<template>
  <div>
    <div style="width: 100%">
      <el-input placeholder="输入姓名"  style="width: 250px" v-model="sname" />
      <el-input placeholder="输入电话"  style="width: 250px" v-model="phone" />
      <el-select v-model="hid" placeholder="选择医院" >
        <el-option
          v-for="item in hospital"
          :key="item.id"
          :value="item.id"
          :label="item.hname"
        />
      </el-select>
      <el-select v-model="did" placeholder="选择科室">
        <el-option
          v-for="item in department"
          :key="item.did"
          :value="item.did"
          :label="item.dname"
        />
      </el-select>
      <el-button @click="getAllSecton" type="primary" icon="el-icon-search"
        >查询</el-button
      >
    </div>
  
    <br /><br />
    <el-table
      ref="multipleTable"
      :data="pageInfo.list"
      tooltip-effect="dark"
      style="width: 80%; margin: 0px auto"
    >
      <el-table-column
        prop="tbUser.phone"
        label="电话号码"
         width="200"
      ></el-table-column>
      <el-table-column prop="tbHospital.hname" label="医院" width="200" ></el-table-column>
      <el-table-column
        prop="tbDepartment.dname"
        label="科室"
         width="200"
      ></el-table-column>
      <el-table-column
        prop="sname"
        label="姓名"
         width="200"
      ></el-table-column>
      <el-table-column
        prop="gender"
        label="性别"
        width="200"
      ></el-table-column>
      <!---操作列--->
       <el-table-column label="操作"  align="center">
        <template slot-scope="scope">
          <el-button size="mini" type="warning" @click="UpdatePassword(scope.row)"
            >重置密码</el-button
          >
          <el-button size="mini" type="danger" @click="Softdel(scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pageInfo.pageNum"
      :page-sizes="[3, 5, 8, 10]"
      :page-size="pageInfo.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="pageInfo.total"
    >
    </el-pagination>
  
  </div>
</template>
<style>
.demo-table-expand {
  font-size: 0;
}
.demo-table-expand label {
  width: 90px;
  color: #99a9bf;
}
.demo-table-expand .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
  width: 50%;
}
</style>
<script>
import { getAll, getAllDepartment, getAllHospital,updatePassword,softdel } from "@/api/Section.js";

export default {
  data() {
    return {
      pageInfo: {
        pageNum: 1,
        pageSize: 10,
      },
      phone: "",
      sname: "",
      did: "",
      hid: "",
      hospital: [],
      department: [],
    };
  },
  methods: {
    Softdel(row){
       softdel(row.sid).then((res)=>{
        if(res.data.code==200){
            alert("删除成功");
             this.getAllSecton();
        }
      });
    },
    UpdatePassword(row){
      updatePassword(row.sid).then((res)=>{
        if(res.data.code==200){
            alert("重置成功");
        }
      });
    },
    getAllSecton() {
      getAll({
        pageNum: this.pageInfo.pageNum,
        pageSize: this.pageInfo.pageSize,
        phone: this.phone,
        sname: this.sname,
        did: this.did,
        hid: this.hid,
      }).then((res) => {
        if (res.data.code == 200) {
          this.pageInfo = res.data.data;
          this.phone = "";
          this.hid = "";
          this.did = "";
          this.sname = "";
        }
      });
    },
    getDepartment() {
      getAllDepartment().then((res) => {
        if (res.data.code == 200) {
          this.department = res.data.data;
        }
      });
    },
    getHospital() {
      getAllHospital().then((res) => {
        if (res.data.code == 200) {
          this.hospital = res.data.data;
        }
      });
    },
    //val=改变之后的条目数
    handleSizeChange(val) {
      this.pageInfo.pageSize = val;
      this.pageInfo.pageNum = 1;
      this.getAllSecton();
    },
    //改变之后的当前页
    handleCurrentChange(val) {
      this.pageInfo.pageNum = val;
      this.getAllSecton();
    },
  },
  mounted() {
    this.getAllSecton();
    this.getDepartment();
    this.getHospital();
  },
};
</script>